package com.sitech.portal.system.dao.ibatis;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sitech.ibnms.core.BaseIbnmsDao;
import com.sitech.portal.system.dao.ISysUserRoleDao;
import com.sitech.portal.system.domain.TblSYS_LOGINMSG;
import com.sitech.portal.system.domain.TblSYS_USER_ROLE;

public class SysUserRoleDaoImpl extends BaseIbnmsDao implements ISysUserRoleDao {

	public void add(TblSYS_LOGINMSG curUser, String[] roleId,
			TblSYS_LOGINMSG user) {
		this.deleteSelectedByUser(roleId, user);
		Map map = new HashMap();
		for (int i = 0; i < roleId.length; i++) {
			map.put("LOGIN_ID", user.getLOGIN_ID());
			map.put("OP_TIME", new Date());
			map.put("ROLE_ID", roleId[i]);
			this.insert("insertForTblSYS_USER_ROLE", map);
		}

	}

	public void update(TblSYS_USER_ROLE tblSYS_USER_ROLE) {
		this.update("update", tblSYS_USER_ROLE);
	}

	public void deleteSelectedByUser(String id[], TblSYS_LOGINMSG user) {
		this.delete("deleteForTblSYS_USER_ROLE",
					user.getUSER_ID_UP());
	}

	public void deleteByUserId(String id[]) {
		if (id != null && id.length > 0) {
			for (int i = 0; i < id.length; i++) {
				this.delete("deleteForTblSYS_USER_ROLE", id[i]);
			}
		}
	}

	public TblSYS_USER_ROLE get(String s, String s1) {
		HashMap hashmap = new HashMap();
		hashmap.put("s", s1.trim());
		hashmap.put("s1", s.trim());
		return (TblSYS_USER_ROLE) this.querySingle("get", hashmap);
	}

	public List findRoleListByUserId(String userId) {
		return this.query("findRoleListByUserId", userId);
	}
}
